﻿using BaseDal;
using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BaseBll
{
    public class StaffBll
    {
        private static readonly Lazy<StaffBll> bll = new Lazy<StaffBll>(() => new StaffBll());
        public static StaffBll Instance { get; } = bll.Value;

        private StaffBll()
        { }

        /// <summary>
        /// 查询数据是否存在
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public bool IsExist(string strWhere)
        {
            return StaffDal.Instance.IsExist(strWhere);
        }

        /// <summary>
        /// 查询分页数据
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageIndex"></param>
        /// <param name="strWhere"></param>
        /// <param name="filedOrder"></param>
        /// <param name="recordCount"></param>
        /// <returns></returns>
        public DataTable GetPageList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return StaffDal.Instance.GetPageList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }

        /// <summary>
        /// 查询数据
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public List<Staff> GetList(string strWhere)
        {
            return StaffDal.Instance.GetList(strWhere);
        }

        /// <summary>
        /// 根据id查询实体类
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Staff GetModelById(int id)
        {
            return StaffDal.Instance.GetModelById(id);
        }

        /// <summary>
        /// 新增人员
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool AddStaff(Staff model)
        {
            return StaffDal.Instance.AddStaff(model);
        }

        /// <summary>
        /// 修改人员
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool UpdateStaff(Staff model)
        {
            return StaffDal.Instance.UpdateStaff(model);
        }

        /// <summary>
        /// 删除人员
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool DeleteStaff(string id, string userName)
        {
            return StaffDal.Instance.DeleteStaff(id, userName);
        }

        /// <summary>
        /// 验证model各字段合法性
        /// </summary>
        /// <param name="model"></param>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        public bool VerifyModel(Staff model, ref string msg)
        {
            if (string.IsNullOrEmpty(model.Name))
            {
                msg = "人员姓名不能为空";
                return false;
            }          

            return true;
        }
    }
}